import request from '@/utils/request'

// 上传图片
export function uploadImage(file) {
  const formData = new FormData()
  formData.append('file', file)
  
  return request({
    url: '/admin/files/upload/image',
    method: 'post',
    data: formData,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  })
}

// 上传文档
export function uploadDocument(file) {
  const formData = new FormData()
  formData.append('file', file)
  
  return request({
    url: '/admin/files/upload/document',
    method: 'post',
    data: formData,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  })
}

// 通用文件上传
export function uploadFile(file, subDir = 'others') {
  const formData = new FormData()
  formData.append('file', file)
  formData.append('subDir', subDir)
  
  return request({
    url: '/admin/files/upload',
    method: 'post',
    data: formData,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  })
}

// 删除文件
export function deleteFile(filePath) {
  return request({
    url: '/admin/files',
    method: 'delete',
    params: { filePath }
  })
}

// 获取文件信息
export function getFileInfo(filePath) {
  return request({
    url: '/admin/files/info',
    method: 'get',
    params: { filePath }
  })
}

// 批量删除文件
export function batchDeleteFiles(filePaths) {
  return request({
    url: '/admin/files/batch',
    method: 'delete',
    data: filePaths
  })
}

// 获取上传配置
export function getUploadConfig() {
  return request({
    url: '/admin/files/config',
    method: 'get'
  })
}